class Popsicle < ActiveRecord::Base		
	validates :type, :presence => true	

	def find_prev_popsicle #Ethan, edited by Adrian
		return self.prev_popsicle.nil? ? nil : Popsicle.find(self.prev_popsicle)
	end
	
	def get_responses#Ethan
		responses = []
		responses << self
		get_responses_recursive(responses, self)
		
		return responses
	end
	
	def get_responses_recursive(list, current)#Ethan
		nextPop = current.find_next_popsicle
		if nextPop.nil?
			return
		else
			list << nextPop
			get_responses_recursive(list, nextPop)
		end
	end
	
	def find_next_popsicle
		return Popsicle.find_by_prev_popsicle(self.id)
		#How to account for it when there is no previous popsicle? Will it just come up with false?
	end
	
	def create_response(entity_id,content)
	# look in child classes for overrides
		raise NotImplementedError
	end	
	
	def is_reply #Created by Adrian
		return !self.prev_popsicle.nil?
	end
	
	def find_original_popsicle #Created by Adrian
		oldPopsicle = self;
		until (popsicle = oldPopsicle.find_prev_popsicle).nil? do oldPopsicle = popsicle end		
		return oldPopsicle
  end

  def find_end_response #Created by Adrian
    oldPopsicle = self
    until (popsicle = oldPopsicle.find_next_popsicle).nil? do oldPopsicle = popsicle end
    return oldPopsicle
  end

end
